import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import sun.net.www.http.HttpClient;

/**
 * Copyright © 2011 Creativor Studio.
 * About license information, please see LICENSE.txt.
 */

/**
 * 
 * @author Nick Zhang
 */
public class HttpRPCDemo
{
	private static final byte[] DEMO_DATA =
			("GET /js1/main.jsp?sid=sCSUqFOkXUXnqfhAnOkkfdXUHAkXmqGf HTTP/1.1\r\n"
					+ "Host: webmail.mail.163.com\r\n"
					+ "User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.6) Gecko/20100626 SUSE/3.6.6-1.2 Firefox/3.6.6\r\n"
					+ "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
					+ "Accept-Language: zh-cn,zh;q=0.5\r\n"
					+ "Accept-Encoding: gzip,deflate\r\n"
					+ "Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7\r\n"
					+ "Keep-Alive: 115\r\n"
					+ "Connection: keep-alive\r\n"
					+ "Content-Length: 3\r\n"
					+ "\r\n"
					+ "123"
					+ "GET /js2/main.jsp?sid=sCSUqFOkXUXnqfhAnOkkfdXUHAkXmqGf HTTP/1.1\r\n"
					+ "Host: webmail.mail.163.com\r\n"
					+ "User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.6) Gecko/20100626 SUSE/3.6.6-1.2 Firefox/3.6.6\r\n"
					+ "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
					+ "Accept-Language: zh-cn,zh;q=0.5\r\n"
					+ "Accept-Encoding: gzip,deflate\r\n"
					+ "Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7\r\n"
					+ "Keep-Alive: 115\r\n"
					+ "Connection: keep-alive\r\n"
					+ "Content-Length: 3\r\n"
					+ "\r\n"
					+ "123"
					+ "GET /js3/main.jsp?sid=sCSUqFOkXUXnqfhAnOkkfdXUHAkXmqGf HTTP/1.1\r\n"
					+ "Host: webmail.mail.163.com\r\n"
					+ "User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.6) Gecko/20100626 SUSE/3.6.6-1.2 Firefox/3.6.6\r\n"
					+ "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
					+ "Accept-Language: zh-cn,zh;q=0.5\r\n"
					+ "Accept-Encoding: gzip,deflate\r\n"
					+ "Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7\r\n"
					+ "Keep-Alive: 115\r\n"
					+ "Connection: keep-alive\r\n"
					+ "Content-Length: 3\r\n"
					+ "\r\n"
					+ "123"
					+ "GET /js4/main.jsp?sid=sCSUqFOkXUXnqfhAnOkkfdXUHAkXmqGf HTTP/1.1\r\n"
					+ "Host: webmail.mail.163.com\r\n"
					+ "User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.6) Gecko/20100626 SUSE/3.6.6-1.2 Firefox/3.6.6\r\n"
					+ "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
					+ "Accept-Language: zh-cn,zh;q=0.5\r\n"
					+ "Accept-Encoding: gzip,deflate\r\n"
					+ "Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7\r\n"
					+ "Keep-Alive: 115\r\n"
					+ "Connection: keep-alive\r\n"
					+ "Content-Length: 3\r\n"
					+ "\r\n"
					+ "123"
					+ "GET /js5/main.jsp?sid=sCSUqFOkXUXnqfhAnOkkfdXUHAkXmqGf HTTP/1.1\r\n"
					+ "Host: webmail.mail.163.com\r\n"
					+ "User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.6) Gecko/20100626 SUSE/3.6.6-1.2 Firefox/3.6.6\r\n"
					+ "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
					+ "Accept-Language: zh-cn,zh;q=0.5\r\n" + "Accept-Encoding: gzip,deflate\r\n"
					+ "Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7\r\n" + "Keep-Alive: 115\r\n"
					+ "Connection: keep-alive\r\n" + "Content-Length: 3\r\n" + "\r\n" + "123")
					.getBytes();
	
	public static void main(String[] args) throws IOException
	{
		URL serverUrl = new URL("http://127.0.0.1:6665/service/method");
		HttpClient httpClient = HttpClient.New(serverUrl);
		OutputStream os = httpClient.getOutputStream();
		os.write(DEMO_DATA);
		os.flush();
		httpClient.closeServer();
	}
}
